/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-06-20
 * Time: 14:01
 */
public class Solution {
    //回文子串
    public int countSubstrings(String s) {
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        int ret = 0;
        for (int i = n-1; i >= 0; i--) {
            for (int j = i; j >= 0; j--) {
                if(s.charAt(i) == s.charAt(j)){
                    dp[i][j] = i + 1 < j ? dp[i+1][j-1] : true;
                }
                if(dp[i][j]){
                    ret++;
                }
            }
        }

        return ret;
    }
}
